package com.kancy.spring.sample.runner;

import com.kancy.spring.boot.ApplicationRunner;
import com.kancy.spring.context.annotation.Autowired;
import com.kancy.spring.context.annotation.Bean;
import com.kancy.spring.context.annotation.Component;
import com.kancy.spring.context.annotation.Order;
import com.kancy.spring.log.Logger;
import com.kancy.spring.log.LoggerFactory;
import com.kancy.spring.sample.bean.BeanA;
import com.kancy.spring.sample.bean.BeanB;
import com.kancy.spring.sample.bean.BeanC;

/**
 * SimpleApplicationRunner
 *
 * @author kancy
 * @date 2020/2/18 12:12
 */
@Order(1)
@Component
public class SimpleApplicationRunner implements ApplicationRunner {

    private static final Logger log = LoggerFactory.getLogger(SimpleApplicationRunner.class);

    @Autowired
    private BeanA beanA;

    @Autowired
    private BeanB beanB;

    @Autowired("beanC1")
    private BeanC beanC1;

    @Autowired("beanC2")
    private BeanC beanC2;

    @Override
    public void run(String[] args) throws Exception {
        beanA.print();
        beanB.print();
        log.info(beanC1.toString());
        log.info(beanC2.toString());
    }

    @Bean("beanC1")
    private BeanC createBeanC1() {
        return new BeanC("I am bean c1!");
    }

    @Bean("beanC2")
    private BeanC createBeanC2() {
        return new BeanC("I am bean c2!");
    }
}
